/*
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.readystatesoftware.systembartint.sample.slice;

import com.readystatesoftware.systembartint.SystemBarTintManager;
import com.readystatesoftware.systembartint.sample.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

public class MainAbilitySlice extends AbilitySlice {
    private Button button, button2;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        ComponentContainer rootLayout = (ComponentContainer) LayoutScatter.getInstance(this).
                parse(ResourceTable.Layout_ability_main, null, false);
        button = (Button)rootLayout.findComponentById(ResourceTable.Id_button);
        button2 = (Button)rootLayout.findComponentById(ResourceTable.Id_button2);

        ShapeElement background = new ShapeElement();
        background.setRgbColor(RgbColor.fromArgbInt(Color.GREEN.getValue()));
        button.setBackground(background);
        // Add a listener for the click event to the control.
        button.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component Component) {
                SystemBarTintTestcase1();
            }
        });

        ShapeElement background2 = new ShapeElement();
        background2.setRgbColor(RgbColor.fromArgbInt(Color.RED.getValue()));
        button2.setBackground(background2);
        // Add a listener for the click event to the control.
        button2.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component Component) {
                SystemBarTintTestcase2();
            }
        });

        super.setUIContent(rootLayout);
    }

    private void SystemBarTintTestcase1() {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        // enable status bar tint
        tintManager.setStatusBarTintEnabled(true);
        // enable navigation bar tint
        tintManager.setNavigationBarTintEnabled(true);
        tintManager.setTintColor(Color.GREEN.getValue());
    }

    private void SystemBarTintTestcase2() {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        // enable status bar tint
        tintManager.setStatusBarTintEnabled(true);
        // enable navigation bar tint
        tintManager.setNavigationBarTintEnabled(true);
        tintManager.setTintColor(Color.RED.getValue());
    }
}
